package com.cqywc.cjadmin.utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;




public class BusinessExceptionResolver implements HandlerExceptionResolver {

	@Override
	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object arg2,
			Exception e) {
		
		String msg=e.getMessage();
		boolean isAjaxRequest = false;  
		ModelAndView modelAndView=new ModelAndView();
		System.out.println(msg);
        if((request.getHeader("x-requested-with"))!=null && request.getHeader("x-requested-with").equals("XMLHttpRequest")){  
            isAjaxRequest = true;  
        }  
       
		if(isAjaxRequest) {
			request.setAttribute("msg", msg);
			 modelAndView.setViewName("forward:/errorajax.do");
			return modelAndView;
		}
		modelAndView.setViewName("admin/error");
		return modelAndView;
	}

}
